package com.gxa.logistics.controller;

import com.gxa.logistics.common.base.PageWrapperDTO;
import com.gxa.logistics.common.base.RespResult;
import com.gxa.logistics.domain.dto.RoleMenuSaveDTO;
import com.gxa.logistics.domain.dto.RoleReqListDTO;
import com.gxa.logistics.domain.dto.RoleSaveDTO;
import com.gxa.logistics.domain.dto.RoleUpdateDTO;
import com.gxa.logistics.domain.vo.RoleVO;
import com.gxa.logistics.service.RoleService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "用户管理-角色权限")
@RestController
@RequestMapping("/role")
@Slf4j
public class RoleController {

    @Autowired
    private RoleService roleService;

    /**
     * 获取角色列表
     */
    @ApiOperation(value = "获取角色列表-分页", notes = "获取角色列表-分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo",value = "当前页码数",defaultValue = "1",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "pageSize",value = "每页显示条数",defaultValue = "10",paramType = "query",dataType = "String")
    })
    @PostMapping("/list")
    public RespResult<PageWrapperDTO<RoleVO>> list(RoleReqListDTO roleReqListDTO){
        return roleService.list(roleReqListDTO);
    }

    @GetMapping("/find")
    public RespResult<List<RoleVO>> find(){
        return RespResult.success(roleService.findAll());
    }
    /**
     * 新增员工
     */
    @ApiOperation(value = "新增保存", notes = "新增保存")
    @PostMapping("/save")
    public RespResult save(@RequestBody @ApiParam(name = "data",value = "添加角色实体") @Validated RoleSaveDTO roleSaveDTO) {
        // 保存
        roleService.insertRole(roleSaveDTO);
        return RespResult.success();
    }

    /**
     * 修改用户
     */
    @ApiOperation(value = "修改保存", notes = "修改保存")
    @PostMapping("/update")
    public RespResult update(@RequestBody @ApiParam(name = "data",value = "修改角色实体") RoleUpdateDTO roleUpdateDTO) {
        roleService.updateRole(roleUpdateDTO);
        return RespResult.success();
    }


    /**
     * 删除角色
     */
    @ApiOperation(value = "删除角色", notes = "删除角色")
    @ApiImplicitParam(name = "role_id",value = "角色id",required = true,dataType = "String",paramType = "path")
    @PostMapping("/delete/{role_id}")
    public RespResult delete(@PathVariable("role_id") Integer roleId){
        roleService.deleteRoleById(roleId);
        return RespResult.success();
    }

    /**
     * 角色授权
     */
    @ApiOperation(value = "角色授权", notes = "角色授权")
    @PostMapping("/authorize")
    public RespResult authorize(@RequestBody @ApiParam(name = "data",value = "角色授权") RoleMenuSaveDTO roleMenuSaveDTO) {
        // 保存
        roleService.authorizeRole(roleMenuSaveDTO);
        return RespResult.success();
    }

}
